import sqlite3

# 连接数据库（文件不存在则自动创建）
conn = sqlite3.connect('mydatabase.db')
cursor = conn.cursor()

# 创建表
cursor.execute('''
    CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY,
        name TEXT NOT NULL,
        email TEXT UNIQUE
    )
''')

# 插入数据
cursor.execute("INSERT INTO users (name, email) VALUES (?, ?)", ('Alice', 'alice@example.com'))
# conn.commit()  # 提交事务

# 查询数据
cursor.execute("SELECT * FROM users")
cf = cursor.fetchall()[0]
print(cursor.fetchall())  # 输出: [(1, 'Alice', 'alice@example.com')]
one = cf[0]
Alice = cf[1]
email = cf[2]
print(one, Alice, email)
# 关闭连接
conn.close()











